package jb02;

import java.util.Scanner;

public class DoWhileDemo {
    public static void main(String[] args) {
        /*
        *   2.do...while:
            1)语法:
                do{
                  语句块/循环体
                }while(boolean);
            2)执行过程:
                先执行语句块，再判断boolean的值，若为true则
                再执行语句块，再判断boolean的值，若为true则
                再执行语句块，以此类推，直到boolean为false时，循环结束*/
        Scanner scan = new Scanner(System.in);
        /**
         * Math.random()-----------0.0到0.999999999999999...double型；
         * *1000-------------------0.0到999.9999999999999...Math.random()*1000
         * +1----------------------1.0到1000.999999999999...Math.random*1000+1
         * (int)-------------------1到1000...(int)(Math。random*1000+1),因为num是int型,所以要强制转成int型；
         */
        int num = (int) (Math.random() * 1000 + 1);//1到1000之内的随机整数
        System.out.println(num);
        int guess;
        do {
            System.out.println("猜一猜:");
            guess=scan.nextInt();
            if (guess>num){
                System.out.println("太大了");
            } else if (guess < num) {
                System.out.println("太小了");
            }else {
                System.out.println("猜对了");
            }
        }while(guess!=num);

    }
}
